"""
@author: xiangping
@contact: xiangpingbu@gmail.com
@time: 2020/1/10 4:37 下午
@file: shaojie_controller
@Desc:
"""
from datetime import datetime
from threading import Thread
from typing import List

from app.database import convert
from app.exts import influxdb


from app.models.po.lugang.lugang_original_po import LuGangQinshiDataPO, LuGangQinshiResultPO
from app.services.business import lugang_biz_service, lugang_qinshi_biz_service
import logging

from flask import Blueprint, request, current_app
from app.controllers.response.response import SuccessResult
from app.exts import ironman_redis as redis
from app.services.business.gaolu_diagnose.ind.abstract_ind import RealTimeInfluxDbInd
from app.utils import string_util, date_util
import pandas as pd
import logging as log

from app.utils.thread import CountDownLatch

bp = Blueprint('lugang_qinshi', __name__, url_prefix="/api/v1/lugang/qinshi")
shaojie_bp = bp


@shaojie_bp.route('/dump', methods=['GET'])
def dump_lugang_data():
    df = pd.read_excel("/Users/lifeng/Downloads/副本历史数据复现.xlsx", sheet_name="侵蚀状态")
    for index, row in df.iterrows():
        time = row['DateTime']
        now = datetime.now()
        hour_end = datetime(time.year, time.month, time.day, time.hour, 59, 59)

        for key, v in row.items():
            if key == 'DateTime': continue

            record: LuGangQinshiResultPO = LuGangQinshiResultPO()
            record.level = "hour"
            record.name = key
            record.value = v
            record.date_time = hour_end
            record.gmt_create = now
            record.gmt_modified = now
            convert.add_one(record)


@shaojie_bp.route('/data', methods=['GET'])
def test_dump_lugang_data():
    import random

    for item in [["CG_LT_GL_GL04_LGWDBG10500TE1245", 300, 310],
                 ["CG_LT_GL_GL04_LGWDBG9500TE1235", 145, 148],
                 ["CG_LT_GL_GL04_LGWDBG8500TE1223", 190, 200],
                 ["CG_LT_GL_GL04_LGWDBG8000TE1207", 140, 150],
                 ["CG_LT_GL_GL04_LGWDBG7500TE1191", 130, 140],
                 ["CG_LT_GL_GL04_LGWDBG7000TE1175", 150, 160],
                 ["CG_LT_GL_GL04_LGWDBG7000TE1161", 90, 100],
                 ["CG_LT_GL_GL04_LDWDBG5700TE1107", 100, 120],
                 ["CG_LT_GL_GL04_LDWDBG5700TE1108", 190, 210],
                 ["CG_LT_GL_GL04_LDWDBG5700TE1109", 270, 290],
                 ["CG_LT_GL_GL04_LDWDBG5700TE1116", 310, 320],
                 ["CG_LT_GL_GL04_LGWDBG10500TE1246", 325, 330],
                 ["CG_LT_GL_GL04_LGWDBG9500TE1236", 170, 180],
                 ["CG_LT_GL_GL04_LGWDBG8500TE1224", 230, 250],
                 ["CG_LT_GL_GL04_LGWDBG8000TE1208", 170, 180],
                 ["CG_LT_GL_GL04_LGWDBG7500TE1192", 160, 180],
                 ["CG_LT_GL_GL04_LGWDBG7000TE1176", 130, 150],
                 ["CG_LT_GL_GL04_LGWDBG7000TE1162", 100, 110],
                 ["CG_LT_GL_GL04_LDWDBG6200TE1132", 160, 180],
                 ["CG_LT_GL_GL04_LDWDBG6200TE1133", 330, 340],
                 ["CG_LT_GL_GL04_LDWDBG6200TE1134", 450, 460],
                 ["CG_LT_GL_GL04_LDWDBG6200TE1141", 490, 510]
                 ]:
        key = item[0]
        redis.hset("lugang_qinshi", key, random.randint(item[1], item[2]))
        redis.hset("lugang_qinshi_update", key, datetime.strftime(datetime.now(), "%Y-%m-%d %H:%M:%S"))
        logging.info(key)

    return SuccessResult(detail="ok")


@shaojie_bp.route('/result', methods=['GET'])
def lugang_qinshi_data():
    """
    炉缸侵蚀状态
    :return:
    """
    time = request.args.get("time")
    direction = request.args.get("direction", "90")

    if time is not None:
        time = datetime.strptime(time, "%Y-%m-%d %H:%M:%S")
        time = datetime(time.year, time.month, time.day, time.hour, 59, 59)

    data = lugang_qinshi_biz_service.get_qinshi_model_data(time, direction)

    group1 = []
    group2 = []
    table = []

    group1.append([0, 11700])
    group1.append([data.get('A',0), 11700]) # A
    group1.append([data.get('B',0), 10200]) # B
    group1.append([data.get('C',0), 9200]) # C
    group1.append([data.get('D',0), 8700]) # D
    group1.append([data.get('E',0), 8200]) # E
    group1.append([data.get('F',0), 7700]) # F
    # group1.append([data['G'], 7210]) # G

    # group2.append([1090, data['H']])
    group2.append([2670, data.get('I',0)])
    group2.append([6650, data.get('J',0)])
    group2.append([6650, 4000])

    table.append(dict(lugang='11700', v1=data.get('A',0), ludi="炉底外圈", v2=data.get('H',0)))
    table.append(dict(lugang='10200', v1=data.get('B',0), ludi="炉底中圈", v2=data.get('I',0)))
    table.append(dict(lugang='9200', v1=data.get('C',0), ludi="炉底内圈", v2=data.get('J',0)))
    table.append(dict(lugang='8700', v1=data.get('D',0)))
    table.append(dict(lugang='8200', v1=data.get('E',0)))
    table.append(dict(lugang='7700', v1=data.get('F',0)))
    # table.append(dict(lugang='7210', v1=data['G']))

    return SuccessResult(detail=dict(group1=group1, group2=group2, table=table))


@shaojie_bp.route('/history', methods=['GET'])
def history_compare():
    """
    历史侵蚀情况
    :return:
    """

    start = request.args.get("start")
    end = request.args.get("end")
    name = request.args.get("name")
    direction = request.args.get("direction", '90')
    results = dict(date=[], value=[])

    if start is not None:
        start = datetime.strptime(start, "%Y-%m-%d %H:%M:%S")
    if end is not None:
        end = datetime.strptime(end, "%Y-%m-%d %H:%M:%S")

    histories: List[LuGangQinshiResultPO] = lugang_qinshi_biz_service.get_qinshi_history(name, start, end, direction)
    for history in histories:
        results['date'].append(history.date_time.strftime("%Y-%m-%d"))
        results['value'].append(history.value)

    return SuccessResult(detail=results)


@shaojie_bp.route('/avgStatus', methods=['GET'])
def lugang_avg_status():
    """
    炉缸均匀状态
    :return:
    """
    start = request.args.get("start")
    end = request.args.get("end")
    if start is not None:
        start = datetime.strptime(start, "%Y-%m-%d %H:%M:%S")
    if end is not None:
        end = datetime.strptime(end, "%Y-%m-%d %H:%M:%S")

    result = {}
    data = []
    result['data'] = data

    group = lugang_qinshi_biz_service.get_qinshi_avg_status(start, end)

    if len(group) > 0:
        zhou_direct_array = [v for k, v in group.items() if k in ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']]
        jing_direct_array = [v for k, v in group.items() if k in ['I', 'J', 'K', 'L', 'M', 'N', 'O']]
        zhou_avg = lugang_qinshi_biz_service._avg("zhou_direct", zhou_direct_array)
        jing_avg = lugang_qinshi_biz_service._avg("jing_direct", jing_direct_array)

        # for i in range(len(group)):
        data.append(dict(area="0-90", zhou=group.get("A", 0), height="11700", jing=group.get("I", 0)))
        data.append(dict(area="90-180", zhou=group.get("B", 0), height="10200", jing=group.get("J", 0)))
        data.append(dict(area="180-270", zhou=group.get("C", 0), height="9200", jing=group.get("K", 0)))
        data.append(dict(area="270-0", zhou=group.get("D", 0), height="8700", jing=group.get("L", 0)))
        data.append(dict(area="0-90(底)", zhou=group.get("E", 0), height="8200", jing=group.get("M", 0)))
        data.append(dict(area="90-180(底)", zhou=group.get("F", 0), height="7700", jing=group.get("N", 0)))
        data.append(dict(area="180-270(底)", zhou=group.get("G", 0), height="7200", jing=group.get("O", 0)))
        data.append(dict(area="270-0(底)", zhou=group.get("H", 0), height="", jing=""))
        data.append(dict(area="整体", zhou=zhou_avg, height="整体", jing=jing_avg))

        return SuccessResult(detail=result)
    return SuccessResult(detail=[])


@shaojie_bp.route('/radar/data/in', methods=['GET'])
def radar_data_in():
    time = request.args.get("time")

    if time is not None:
        time = datetime.strptime(time, "%Y-%m-%d %H:%M:%S")
        time = datetime(time.year, time.month, time.day, time.hour, 59, 59)

    data_matrix = {
        "炉底一层": ["CG_LT_GL_GL04_LDWDBG5700TE1108", "CG_LT_GL_GL04_LDWDBG5700TE1111", "CG_LT_GL_GL04_LDWDBG5700TE1114",
                 "CG_LT_GL_GL04_LDWDBG5700TE1118", "CG_LT_GL_GL04_LDWDBG5700TE1121", "CG_LT_GL_GL04_LDWDBG6200TE1124",
                 "CG_LT_GL_GL04_LDWDBG6200TE1127", "CG_LT_GL_GL04_LDWDBG6200TE1130"],

        "7210": ["CG_LT_GL_GL04_LGWDBG7000TE1162", "CG_LT_GL_GL04_LGWDBG6500TE1160", "CG_LT_GL_GL04_LGWDBG7000TE1166",
                 "CG_LT_GL_GL04_LGWDBG7000TE1164", "CG_LT_GL_GL04_LGWDBG7000TE1170", "CG_LT_GL_GL04_LGWDBG7000TE1168",
                 "CG_LT_GL_GL04_LGWDBG6500TE1158", "CG_LT_GL_GL04_LGWDBG7000TE1172"],

        "7700": ["CG_LT_GL_GL04_LGWDBG7000TE1176", "CG_LT_GL_GL04_LGWDBG7000TE1174", "CG_LT_GL_GL04_LGWDBG7500TE1180",
                 "CG_LT_GL_GL04_LGWDBG7500TE1178", "CG_LT_GL_GL04_LGWDBG7500TE1186", "CG_LT_GL_GL04_LGWDBG7500TE1184",
                 "CG_LT_GL_GL04_LGWDBG7500TE1182", "CG_LT_GL_GL04_LGWDBG7500TE1188"],

        "8200": ["CG_LT_GL_GL04_LGWDBG7500TE1192", "CG_LT_GL_GL04_LGWDBG7500TE1190", "CG_LT_GL_GL04_LGWDBG8000TE1196",
                 "CG_LT_GL_GL04_LGWDBG8000TE1194", "CG_LT_GL_GL04_LGWDBG8000TE1202", "CG_LT_GL_GL04_LGWDBG8000TE1200",
                 "CG_LT_GL_GL04_LGWDBG8000TE1198", "CG_LT_GL_GL04_LGWDBG8000TE1204"],

        "8700": ["CG_LT_GL_GL04_LGWDBG8000TE1208", "CG_LT_GL_GL04_LGWDBG8000TE1206", "CG_LT_GL_GL04_LGWDBG8500TE1212",
                 "CG_LT_GL_GL04_LGWDBG8500TE1210", "CG_LT_GL_GL04_LGWDBG8500TE1218", "CG_LT_GL_GL04_LGWDBG8500TE1216",
                 "CG_LT_GL_GL04_LGWDBG8500TE1214", "CG_LT_GL_GL04_LGWDBG8500TE1220"],

        "9200": ["CG_LT_GL_GL04_LGWDBG8500TE1224", "CG_LT_GL_GL04_LGWDBG9500TE1226", "CG_LT_GL_GL04_LGWDBG9500TE1226",
                 "CG_LT_GL_GL04_LGWDBG9500TE1230", "CG_LT_GL_GL04_LGWDBG9500TE1230", "CG_LT_GL_GL04_LGWDBG9500TE1228",
                 "CG_LT_GL_GL04_LGWDBG8500TE1222", "CG_LT_GL_GL04_LGWDBG9500TE1232"],

        "10200": ["CG_LT_GL_GL04_LGWDBG9500TE1236", "CG_LT_GL_GL04_LGWDBG10500TE1238",
                  "CG_LT_GL_GL04_LGWDBG10500TE1238", "CG_LT_GL_GL04_LGWDBG10500TE1242",
                  "CG_LT_GL_GL04_LGWDBG10500TE1242", "CG_LT_GL_GL04_LGWDBG9500TE1234", "CG_LT_GL_GL04_LGWDBG9500TE1234",
                  "CG_LT_GL_GL04_LGWDBG10500TE1244"],

        "11700": ["CG_LT_GL_GL04_LGWDBG10500TE1248", "CG_LT_GL_GL04_LGWDBG11500TE1250",
                  "CG_LT_GL_GL04_LGWDBG11500TE1250", "CG_LT_GL_GL04_LGWDBG11500TE1254",
                  "CG_LT_GL_GL04_LGWDBG11500TE1254", "CG_LT_GL_GL04_LGWDBG11500TE1252",
                  "CG_LT_GL_GL04_LGWDBG10500TE1246", "CG_LT_GL_GL04_LGWDBG10500TE1246"]

    }

    indicators = [dict(name=k) for k, v in data_matrix.items()]

    data = []
    group = lugang_qinshi_biz_service.get_qinshi_model_data_area(time)
    for indicator in indicators:
        name = indicator['name']

        variable_list = data_matrix[name]
        variable_list.reverse()
        value_list = [float(group.get(variable_name, 0)) for variable_name in variable_list]
        item = dict(name=name, value=value_list)
        data.append(item)

    result = dict(legend=list(data_matrix.keys()), indicator=indicators, data=data)

    return SuccessResult(detail=result)


@shaojie_bp.route('/radar/data/out', methods=['GET'])
def radar_data_out():
    time = request.args.get("time")

    if time is not None:
        time = datetime.strptime(time, "%Y-%m-%d %H:%M:%S")
        time = datetime(time.year, time.month, time.day, time.hour, 59, 59)

    data_matrix = {
        "炉底一层": ["CG_LTGL_GL04_LDWDBG5700TE1107", "CG_LTGL_GL04_LDWDBG5700TE1110", "CG_LTGL_GL04_LDWDBG5700TE1113",
                 "CG_LTGL_GL04_LDWDBG5700TE1117	", "CG_LTGL_GL04_LDWDBG5700TE1120	",
                 "CG_LTGL_GL04_LDWDBG5700TE1123	", "CG_LTGL_GL04_LDWDBG6200TE1126	",
                 "CG_LTGL_GL04_LDWDBG6200TE1129"],

        "7210": ["CG_LT_GL_GL04_LGWDBG7000TE1161", "CG_LT_GL_GL04_LGWDBG6500TE1159", "CG_LT_GL_GL04_LGWDBG7000TE1169",
                 "CG_LT_GL_GL04_LGWDBG7000TE1169", "CG_LT_GL_GL04_LGWDBG7000TE1167", "CG_LT_GL_GL04_LGWDBG7000TE1167",
                 "CG_LT_GL_GL04_LGWDBG6500TE1157", "CG_LT_GL_GL04_LGWDBG7000TE1171"],

        "7700": ["CG_LT_GL_GL04_LGWDBG7000TE1175", "CG_LT_GL_GL04_LGWDBG7000TE1173", "CG_LT_GL_GL04_LGWDBG7500TE1179",
                 "CG_LT_GL_GL04_LGWDBG7500TE1177", "CG_LT_GL_GL04_LGWDBG7500TE1185", "CG_LT_GL_GL04_LGWDBG7500TE1183",
                 "CG_LT_GL_GL04_LGWDBG7500TE1181", "CG_LT_GL_GL04_LGWDBG7500TE1187"],

        "8200": ["CG_LT_GL_GL04_LGWDBG7500TE1191", "CG_LT_GL_GL04_LGWDBG7500TE1189", "CG_LT_GL_GL04_LGWDBG8000TE1195",
                 "CG_LT_GL_GL04_LGWDBG8000TE1193", "CG_LT_GL_GL04_LGWDBG8000TE1201", "CG_LT_GL_GL04_LGWDBG8000TE1199",
                 "CG_LT_GL_GL04_LGWDBG8000TE1197", "CG_LT_GL_GL04_LGWDBG8000TE1203"],

        "8700": ["CG_LT_GL_GL04_LGWDBG8000TE1207", "CG_LT_GL_GL04_LGWDBG8000TE1205", "CG_LT_GL_GL04_LGWDBG8500TE1211",
                 "CG_LT_GL_GL04_LGWDBG8500TE1209", "CG_LT_GL_GL04_LGWDBG8500TE1217", "CG_LT_GL_GL04_LGWDBG8500TE1215",
                 "CG_LT_GL_GL04_LGWDBG8500TE1213", "CG_LT_GL_GL04_LGWDBG8500TE1219"],

        "9200": ["G_LT_GL_GL04_LGWDBG8500TE1223", "CG_LT_GL_GL04_LGWDBG9500TE1225", "CG_LT_GL_GL04_LGWDBG9500TE1225",
                 "CG_LT_GL_GL04_LGWDBG9500TE1229", "CG_LT_GL_GL04_LGWDBG9500TE1229", "CG_LT_GL_GL04_LGWDBG9500TE1227",
                 "CG_LT_GL_GL04_LGWDBG8500TE1221", "CG_LT_GL_GL04_LGWDBG9500TE1231"],

        "10200": ["CG_LT_GL_GL04_LGWDBG9500TE1235", "CG_LT_GL_GL04_LGWDBG10500TE1237",
                  "CG_LT_GL_GL04_LGWDBG10500TE1237", "CG_LT_GL_GL04_LGWDBG10500TE1241",
                  "CG_LT_GL_GL04_LGWDBG10500TE1241", "CG_LT_GL_GL04_LGWDBG9500TE1233", "CG_LT_GL_GL04_LGWDBG9500TE1233",
                  "CG_LT_GL_GL04_LGWDBG10500TE1243"],

        "11700": ["CG_LT_GL_GL04_LGWDBG10500TE1247", "CG_LT_GL_GL04_LGWDBG11500TE1249",
                  "CG_LT_GL_GL04_LGWDBG11500TE1249", "CG_LT_GL_GL04_LGWDBG11500TE1253",
                  "CG_LT_GL_GL04_LGWDBG11500TE1253", "CG_LT_GL_GL04_LGWDBG11500TE1251",
                  "CG_LT_GL_GL04_LGWDBG10500TE1245", "CG_LT_GL_GL04_LGWDBG10500TE1245"]

    }

    indicators = [dict(name=k) for k, v in data_matrix.items()]

    data = []
    group = lugang_qinshi_biz_service.get_qinshi_model_data_area(time)
    for indicator in indicators:
        name = indicator['name']

        variable_list = data_matrix[name]
        variable_list.reverse()
        value_list = [float(group.get(variable_name, 0)) for variable_name in variable_list]
        item = dict(name=name, value=value_list)
        data.append(item)

    result = dict(legend=list(data_matrix.keys()), indicator=indicators, data=data)
    return SuccessResult(detail=result)


@shaojie_bp.route('/radar/data/body', methods=['GET'])
def radar_data_body():
    """
    炉腹,炉腰,炉身雷达图
    """

    class SubThread(Thread):
        def __init__(self, name, latch, params):
            Thread.__init__(self)
            self.name = name
            self.latch = latch
            self.params = params
            self.result = 0

        def run(self):
            name = self.name
            try:
                influxdb_client = influxdb.get_client()
                params = self.params

                instance: RealTimeInfluxDbInd = RealTimeInfluxDbInd(influxdb_client, params)
                value = instance.get_result()
                self.result = value
                logging.info("{}:{}".format(name,value))
            except Exception as e:
                log.error("fail to get result of {}. {}".format(name, e), exc_info=1)
            self.latch.countDown()
            logging.info("current count {}".format(self.latch.count))

    data_matrix = {
        "6200": ['CG_LT_GL_GL04_6200WD000090DB1', 'CG_LT_GL_GL04_6200WD000090DB2', 'CG_LT_GL_GL04_6200WD090180DN1',
                 'CG_LT_GL_GL04_6200WD090180DN2', 'CG_LT_GL_GL04_6200WD180270XN1', 'CG_LT_GL_GL04_6200WD180270XN2',
                 'CG_LT_GL_GL04_6200WD000270XB1', 'CG_LT_GL_GL04_8110WD000270XB3'],
        "8110": ['CG_LT_GL_GL04_8110WD000090DB1', 'CG_LT_GL_GL04_8110WD000090DB2', 'CG_LT_GL_GL04_8110WD090180DN1',
                 'CG_LT_GL_GL04_8110WD090180DN2', 'CG_LT_GL_GL04_8110WD180270XN1', 'CG_LT_GL_GL04_8110WD180270XN2',
                 'CG_LT_GL_GL04_8110WD000270XB1', 'CG_LT_GL_GL04_8110WD000270XB3'],
        "10135": ['CG_LT_GL_GL04_10135WD000090DB1', 'CG_LT_GL_GL04_10135WD000090DB2', 'CG_LT_GL_GL04_10135WD090180DN1',
                  'CG_LT_GL_GL04_10135WD090180DN2', 'CG_LT_GL_GL04_10135WD180270XN2', 'CG_LT_GL_GL04_10135WD180270XN2',
                  'CG_LT_GL_GL04_10135WD000270XB1', 'CG_LT_GL_GL04_17187WD000270XB3'],
        "17187": ['CG_LT_GL_GL04_17187WD000090DB1', 'CG_LT_GL_GL04_17187WD000090DB2', 'CG_LT_GL_GL04_17187WD090180DN1',
                  'CG_LT_GL_GL04_17187WD090180DN2', 'CG_LT_GL_GL04_17187WD180270XN1', 'CG_LT_GL_GL04_17187WD180270XN2',
                  'CG_LT_GL_GL04_17187WD000270XB1', 'CG_LT_GL_GL04_17187WD000270XB3'],
        "19507": ['CG_LT_GL_GL04_19507WD000090DB1', 'CG_LT_GL_GL04_19507WD000090DB2', 'CG_LT_GL_GL04_19507WD090180DN1',
                  'CG_LT_GL_GL04_19507WD090180DN2', 'CG_LT_GL_GL04_19507WD180270XN1', 'CG_LT_GL_GL04_19507WD180270XN2',
                  'CG_LT_GL_GL04_19507WD000270XB1', 'CG_LT_GL_GL04_19507WD000270XB3'],
        "21704": ['CG_LT_GL_GL04_21704WD000090DB1', 'CG_LT_GL_GL04_21704WD000090DB2', 'CG_LT_GL_GL04_21704WD090180DN1',
                  'CG_LT_GL_GL04_21704WD090180DN2', 'CG_LT_GL_GL04_21704WD180270XN1', 'CG_LT_GL_GL04_21704WD180270XN2',
                  'CG_LT_GL_GL04_21704WD000270XB1', 'CG_LT_GL_GL04_21704WD000270XB3'],
        "24145": ['CG_LT_GL_GL04_24145WD000090DB1', 'CG_LT_GL_GL04_24145WD000090DB2', 'CG_LT_GL_GL04_24145WD090180DN1',
                  'CG_LT_GL_GL04_24145WD090180DN2', 'CG_LT_GL_GL04_24145WD180270XN1', 'CG_LT_GL_GL04_24145WD180270XN2',
                  'CG_LT_GL_GL04_24145WD000270XB1', 'CG_LT_GL_GL04_24145WD000270XB3'],
        "26275": ['CG_LT_GL_GL04_26275WD000090DB1', 'CG_LT_GL_GL04_26275WD000090DB2', 'CG_LT_GL_GL04_26275WD090180DN1',
                  'CG_LT_GL_GL04_26275WD090180DN2', 'CG_LT_GL_GL04_26275WD180270XN1', 'CG_LT_GL_GL04_26275WD180270XN2',
                  'CG_LT_GL_GL04_26275WD000270XB1', 'CG_LT_GL_GL04_26275WD000270XB3'],
        "29835": ['CG_LT_GL_GL04_29835WD000090DB1', 'CG_LT_GL_GL04_29835WD000090DB1', 'CG_LT_GL_GL04_29835WD090180DN1',
                  'CG_LT_GL_GL04_29835WD090180DN2', 'CG_LT_GL_GL04_29835WD180270XN1', 'CG_LT_GL_GL04_29835WD180270XN2',
                  'CG_LT_GL_GL04_29835WD000270XB1', 'CG_LT_GL_GL04_29835WD000270XB3'],
        "32595": ['CG_LT_GL_GL04_32595WD000090DB1', 'CG_LT_GL_GL04_32595WD000090DB1', 'CG_LT_GL_GL04_32595WD090180DN1',
                  'CG_LT_GL_GL04_32595WD090180DN2', 'CG_LT_GL_GL04_32595WD180270XN1', 'CG_LT_GL_GL04_32595WD180270XN2',
                  'CG_LT_GL_GL04_32595WD000270XB1', 'CG_LT_GL_GL04_32595WD000270XB3'],
        "34800": ['CG_LT_GL_GL04_34800WD000090DB1', 'CG_LT_GL_GL04_34800WD000090DB2', 'CG_LT_GL_GL04_34800WD090180DN1',
                  'CG_LT_GL_GL04_34800WD090180DN1', 'CG_LT_GL_GL04_34800WD180270XN1', 'CG_LT_GL_GL04_34800WD180270XN2',
                  'CG_LT_GL_GL04_34800WD000270XB1', 'CG_LT_GL_GL04_34800WD000270XB3'],
    }

    latch = CountDownLatch(11 * 8)
    thread_list = []
    for key, value in data_matrix.items():
        for v in value:
            from datetime import timedelta
            dt_start_tz = date_util.dt_to_str(date_util.get_start_of_day(datetime.now()) - timedelta(hours=8,minutes=3),
                                              '%Y-%m-%dT%H:%M:%SZ')
            dt_end_tz = date_util.dt_to_str(date_util.get_start_of_day(datetime.now()) + timedelta(hours=8,minutes=1),
                                            '%Y-%m-%dT%H:%M:%SZ')
            params = dict(ind_name=v, dt_start_tz=dt_start_tz, dt_end_tz=dt_end_tz)
            thread = SubThread(v, latch, params)
            thread.start()
            thread_list.append(thread)
    latch.await()

    result = {thread.name: thread.result for thread in thread_list}
    value_matrix =  {}
    for key, value in data_matrix.items():
        value_matrix[key] = [ round(result[v],2) for v in value]

    return SuccessResult(detail=value_matrix)
